{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "92106643",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "ChatDeepSeek(client=<openai.resources.chat.completions.completions.Completions object at 0x000002B8E40E5C30>, async_client=<openai.resources.chat.completions.completions.AsyncCompletions object at 0x000002B8E40E62C0>, root_client=<openai.OpenAI object at 0x000002B8E1A89F00>, root_async_client=<openai.AsyncOpenAI object at 0x000002B8E40E6290>, model_name='deepseek-chat', temperature=0.0, model_kwargs={}, max_retries=2, api_key=SecretStr('**********'), api_base='https://api.deepseek.com/v1')"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import os\n",
    "\n",
    "os.environ[\"DEEPSEEK_API_KEY\"] = \"sk-ccd1af6c1d6e4db28f206c1c52972b6e\"\n",
    "\n",
    "from langchain_deepseek import ChatDeepSeek\n",
    "\n",
    "llm = ChatDeepSeek(\n",
    "    model=\"deepseek-chat\",\n",
    "    temperature=0,\n",
    "    max_tokens=None,\n",
    "    timeout=None,\n",
    "    max_retries=2,\n",
    "    # other params...\n",
    ")\n",
    "\n",
    "llm"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "3cec3a11",
   "metadata": {},
   "outputs": [],
   "source": [
    "template_string = \"\"\"你是一个翻译专家，请将文本翻译成要求的语言。\n",
    "翻译的语言是{input_language}。\n",
    "文本：```{text}```\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "f1888cd2",
   "metadata": {},
   "outputs": [],
   "source": [
    "text = \"你好，今天晚上吃什么？\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "dd515f04",
   "metadata": {},
   "outputs": [],
   "source": [
    "from langchain.prompts import ChatPromptTemplate\n",
    "\n",
    "prompt_template = ChatPromptTemplate.from_template(template_string)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "26ea5d4c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "PromptTemplate(input_variables=['input_language', 'text'], input_types={}, partial_variables={}, template='你是一个翻译专家，请将文本翻译成要求的语言。\\n翻译的语言是{input_language}。\\n文本：```{text}```\\n')"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "prompt_template.messages[0].prompt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "ea86388e",
   "metadata": {},
   "outputs": [],
   "source": [
    "prompt = prompt_template.format_messages(input_language=\"English\", text=text)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "ba798097",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'list'>\n"
     ]
    }
   ],
   "source": [
    "print(type(prompt))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "fe87eca2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'langchain_core.messages.human.HumanMessage'>\n"
     ]
    }
   ],
   "source": [
    "print(type(prompt[0]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "b2ef1a98",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "content='你是一个翻译专家，请将文本翻译成要求的语言。\\n翻译的语言是English。\\n文本：```你好，今天晚上吃什么？```\\n' additional_kwargs={} response_metadata={}\n"
     ]
    }
   ],
   "source": [
    "print(prompt[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "bca66da6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello, what's for dinner tonight?\n"
     ]
    }
   ],
   "source": [
    "# res = llm(prompt)\n",
    "res = llm.invoke(prompt)\n",
    "\n",
    "print(res.content)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "61564655",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'gift': False, 'delivery_days': 3, 'price_value': 'pretty affordable'}"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "{\n",
    "    \"gift\":False,\n",
    "    \"delivery_days\":3,\n",
    "    \"price_value\":\"pretty affordable\"\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a3740f49",
   "metadata": {},
   "outputs": [],
   "source": [
    "customer_review = \"\"\"\\\n",
    "\n",
    "\"\"\"\n",
    "\n",
    "review_template = \"\"\"\\\n",
    "For the following text, extract the following information:\n",
    "\n",
    "\n",
    "\n",
    "text: {text}\"\"\"\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "langchain_learn",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.18"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
